<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 表单行内添加事件 onsubmit="return true" 当表单提交时返回true,默认是true-->
    <form action="" onsubmit="return true" method="get">
        <p>
            <label for="username">用户名:</label>
            <input type="text" name="userName" id="userName">
        </p>
        <p>
            <label for="password">密码:</label>
            <input type="password" name="password" id="password">
        </p>
        <p>
            <input type="radio" name="sex" value="男">男
            <input type="radio" name="sex" value="女">女
        </p>
        <select name="city" id="city">
            <option value="">郑州</option>
            <option value="">安阳</option>
            <option value="">信阳</option>
            <option value="">开封</option>
        </select>
        <p>
            <input type="submit" value="提交">
            <input type="button" value="按钮" id="butt">
        </p>
    </form>
</body>
<script>
    var form=document.getElementsByTagName('form')[0];
    var city=document.getElementById('city');
    var username=document.getElementById('userName');
    //内容发生改变时触发
    //onchange 输入框光标离开才改变内容,选择性的直接选择触发
    userName.onchange=function(){
        console.log('内容发生改变');
    }

    //获取焦点触发
    userName.onfocus=function(){
        console.log('获取焦点');
    }

    //失去焦点触发
    userName.onblur=function(){
        console.log('失去焦点');
    }

    //oninput实时检测输入事件 value获取输入框内容
    userName.oninput=function(){
        console.log(userName.value);
    }

    form.onsubmit=function(e){
        console.log('表单提交了');
        // e.preventDefault(); //阻止表单提交
        return false;//阻止表单提交
    }
</script>

</html>